<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img src="../assets/img/menuicon.png" alt />
        <span>vue权限demo</span>
      </div>
      <el-button style="background:white;color:black"  type="info" @click="logout">{{ username }}退出</el-button>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <!-- <div class="toggle-button" @click="toggleCollapse">|||</div> -->
        <!-- 侧边栏菜单区域 -->
        <el-menu
          :default-active="$route.path"
          class="elMenu"
          background-color="#fff"
          text-color="#B0B0B2"
          active-text-color="#000"
          :unique-opened="true"
          router
          ref="elMenu"
        >
          <!-- 递归动态菜单 -->
          <myitem :data="menulist"></myitem>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapState } from 'vuex'
import myitem from '@/components/myitem'
export default {
  components: {
    myitem
  },
  data() {
    return {
      // 左侧菜单数据
      menulist: [],
      // 是否折叠
      isCollapse: false,
      // 被激活的链接地址
      activePath: ''
    }
  },
  created() {
    // this.activePath = window.sessionStorage.getItem('activePath')
    this.menulist = this.$router.options.routes.filter(v => {
      return v.isShow
    })
  },
  methods: {
    logout() {
      sessionStorage.clear()
      this.$router.push('/login')
      window.location.reload()
    },
    // 保存链接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  },
  computed: {
    ...mapState(['rightList', 'username'])
  }
}
</script>

<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #334eb4;;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: white;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #eaedf1;
}

.iconfont {
  margin-right: 10px;
}

.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
